package com.IT.servletJsp.medicine;

import com.IT.entity.Medicine;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

@WebServlet(value = "/admin/queryMedicine")
public class queryMedicineJsp extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset = utf-8");

        PrintWriter printWriter = response.getWriter();
        List<Medicine> medicineList = (List<Medicine>) request.getAttribute("medicineList");


        printWriter.print("<!DOCTYPE html>");
        printWriter.print("<html>");
        printWriter.print("	<head>");
        printWriter.print("		<meta charset='utf-8'>");
        printWriter.print("		<title>queryMedicine</title>");
        printWriter.print("	</head>");
        printWriter.print("	<body>");
        /*printWriter.print("		<h1 align='center'>medicine列表</h1>");
        printWriter.print("		<hr >");*/
        printWriter.print("		<table border='1px' align='center' width='50%'>");
        printWriter.print("			<tr>");
        printWriter.print("				<td>序号</td>");
        printWriter.print("				<td>名称</td>");
        printWriter.print("				<td>创建时间</td>");
        printWriter.print("				<td>修改时间</td>");
        printWriter.print("			</tr>");



        int i = 1;
        for(Medicine medicine : medicineList){

            printWriter.print("			<tr>");
            printWriter.print("				<td>"+(i++)+"</td>");
            printWriter.print("				<td>"+medicine.getName()+"</td>");
            printWriter.print("				<td>"+medicine.getCreateDate()+"</td>");
            printWriter.print("				<td>"+medicine.getUpdateDate()+"</td>");
            printWriter.print("			</tr>");


            /*printWriter.print("id:"+medicine.getId()+"&emsp;");
            printWriter.print("name:"+medicine.getName()+"&emsp;");
            printWriter.print("createDate:"+medicine.getCreateDate()+"&emsp;");
            printWriter.print("updateDate:"+medicine.getUpdateDate()+"<br/>");*/
        }

        printWriter.print("<tr><td>");
        printWriter.print("        <a href='adminInterface.html'><input type='button' value='后退'/></a>");
        printWriter.print("</td></tr>");


        printWriter.print("		</table>");
        printWriter.print("	</body>");
        printWriter.print("</html>");
    }
}
